package com.ffyc.resale.web;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ffyc.resale.dao.GoodTypesDao;
import com.ffyc.resale.model.GoodType;
import com.ffyc.resale.model.GoodTypes;
import com.ffyc.resale.model.Result;
import com.ffyc.resale.service.GoodTypeService;
import org.apache.ibatis.annotations.ResultMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/goodtype")
public class GoodTypeController {
    @Autowired
    GoodTypeService goodTypeService;

    @GetMapping("/getTab")
    public Result getTab(){
        List<GoodType> tab = goodTypeService.getTab();
        return new Result(200,"成功",tab);
    }
    @PostMapping("/add")
    public Result add(@RequestBody GoodType type){
        goodTypeService.add(type);
        return new Result(200,"添加成功",null);
    }
    @PostMapping("/update")
    public Result update(@RequestBody GoodType type){
        goodTypeService.update(type);
        return new Result(200,"修改成功",null);
    }
    @GetMapping("/delete")
    public Result delete(Integer id){
        if(goodTypeService.delete(id)){
            return new Result(200,"删除成功",null);
        }
        return new Result(201,"当前分类下有二级类",null);
    }
    @PostMapping("/getSubtype")
    public Result getSubtype(@RequestBody GoodTypes goodTypes){
        Page<GoodTypes> page = goodTypeService.getSubtype(goodTypes);
        return new Result(200,"查询成功",page);
    }
    @GetMapping("/deleteSubtype")
    public Result deleteSubtype(Integer id){
        if (goodTypeService.deleteSubtype(id)){
            return new Result(200,"删除成功",null);
        }
        return new Result(201,"删除失败，当前类下有商品",null);
    }
    @PostMapping("/updateSubtype")
    public Result updateSubtype(@RequestBody GoodTypes goodTypes){
        goodTypeService.updateSubtype(goodTypes);
        return new Result(200,"修改成功",null);
    }
    @PostMapping("/addSubtype")
    public Result addSubtype(@RequestBody GoodTypes goodTypes){
        goodTypeService.addSubtype(goodTypes);
        return new Result(200,"添加成功",null);
    }

}
